package com.h3c.tj_nsh.UI.Activities;

import android.os.Bundle;
import android.support.v4.app.FragmentTabHost;
import android.widget.FrameLayout;
import android.widget.TabHost;

import com.h3c.tj_nsh.Constant;
import com.h3c.tj_nsh.R;
import com.h3c.tj_nsh.Widget.TabIndicatorView;

import butterknife.Bind;
import butterknife.ButterKnife;
/**
 * 部门经理的基础页面
 */
public class DepartmentLeaderActivity extends BaseActivity implements TabHost.OnTabChangeListener {


    @Bind(R.id.activity_home_container)
    FrameLayout mActivityHomeContainer;
    @Bind(android.R.id.tabcontent)
    FrameLayout mTabcontent;
    @Bind(android.R.id.tabhost)
    FragmentTabHost mTabhost;
    private TabIndicatorView mAlarmIndicator, mEquipmentIndicator, mTAB_ITSMIndicator, mNotifyIndicator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_department);
        ButterKnife.bind(this);


        initTabHost();

    }


    private void initTabHost() {
        // 1. 初始化TabHost
        mTabhost.setup(this, getSupportFragmentManager(),
                R.id.activity_home_container);
        TabHost.TabSpec mAlarmSpec = mTabhost.newTabSpec(Constant.TAB_ALARM);
        mAlarmIndicator = new TabIndicatorView(this);
        mAlarmIndicator.setTabTitle(Constant.TAB_ALARM);
        mAlarmIndicator.setTabIcon(R.drawable.icon_signal);
        mAlarmSpec.setIndicator(mAlarmIndicator);

        TabHost.TabSpec mEquipmentSpec = mTabhost.newTabSpec(Constant.TAB_EQUIPMENT);
        mEquipmentIndicator = new TabIndicatorView(this);
        mEquipmentIndicator.setTabTitle(Constant.TAB_EQUIPMENT);
        mEquipmentIndicator.setTabIcon(R.drawable.icon_signal);
        mEquipmentSpec.setIndicator(mEquipmentIndicator);

        TabHost.TabSpec mITSMSpec = mTabhost.newTabSpec(Constant.TAB_ITSM);
        mTAB_ITSMIndicator = new TabIndicatorView(this);
        mTAB_ITSMIndicator.setTabTitle(Constant.TAB_ITSM);
        mTAB_ITSMIndicator.setTabIcon(R.drawable.icon_signal);
        mITSMSpec.setIndicator(mTAB_ITSMIndicator);

        TabHost.TabSpec mNotifySpec = mTabhost.newTabSpec(Constant.TAB_NOTIFY);
        mNotifyIndicator = new TabIndicatorView(this);
        mNotifyIndicator.setTabTitle(Constant.TAB_NOTIFY);
        mNotifyIndicator.setTabIcon(R.drawable.icon_signal);
        mNotifySpec.setIndicator(mNotifyIndicator);

        //添加TabSpec
        mTabhost.addTab(mAlarmSpec, Fragmen.class, null);
        mTabhost.addTab(mEquipmentSpec, Fragmen.class, null);
        mTabhost.addTab(mITSMSpec, Fragmen.class, null);
        mTabhost.addTab(mNotifySpec, Fragmen.class, null);
        //去除分割线
        mTabhost.getTabWidget().setDividerDrawable(android.R.color.white);
        // 初始化 tab选中
        mTabhost.setCurrentTabByTag(Constant.TAB_ALARM);
        mAlarmIndicator.setTabSelected(true);

        // 设置tab切换的监听
        mTabhost.setOnTabChangedListener(DepartmentLeaderActivity.this);
    }

    @Override
    public void onTabChanged(String tag) {
        mAlarmIndicator.setTabSelected(false);
        mEquipmentIndicator.setTabSelected(false);
        mNotifyIndicator.setTabSelected(false);
        mTAB_ITSMIndicator.setTabSelected(false);

        if (Constant.TAB_ALARM.equals(tag)) {
            mAlarmIndicator.setTabSelected(true);
        } else if (Constant.TAB_ITSM.equals(tag)) {
            mTAB_ITSMIndicator.setTabSelected(true);
        } else if (Constant.TAB_NOTIFY.equals(tag)) {
            mNotifyIndicator.setTabSelected(true);
        } else if (Constant.TAB_EQUIPMENT.equals(tag)) {
            mEquipmentIndicator.setTabSelected(true);
        }
    }
}
